package jdbc.three.dao.impl;

import jdbc.three.beans.Account;
import jdbc.three.dao.AccountDao;
import jdbc.three.mapper.AccountMapper;
import jdbc.three.util.tmp.Tmp;

import java.sql.SQLException;
import java.util.List;

public class AccountDaoImpl implements AccountDao {
    @Override
    public int insertAccount(Account a) throws SQLException {
        String sql="insert into account values(?,?,?)";
        return Tmp.update(sql,a.getId(),a.getName(),a.getMoney());
    }

    @Override
    public Account selectById(int id)throws SQLException {
        String sql="select * from account where id=?";
        List<Account>list= Tmp.query(sql,new AccountMapper(),id);
        return list.isEmpty()?null:list.get(0);
    }

    @Override
    public int updateById(int id, double m)throws SQLException {
        String sql="update account set money=? where id=?";
        return Tmp.update(sql,m,id);
    }
}
